<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('人才库新增')" />
	<th:block th:include="include :: businessCSS" />
</head>
<body>
	<input type="hidden" id="cid">
	<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	<div class="layui-btn-container" style="float: right;">
		<input class="layui-btn layui-table-tools" type="button" lay-submit="" lay-filter="btn_save" value="保存">
    </div>
<th:block th:include="include :: footer" />	
<th:block th:include="include :: businessJS" />	
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" lay-event="del">&nbsp;删除</a>	
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" shiro:hasPermission="hr:talentpool:add">
    	<p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增明细</span></p>
	</div>
	<div class="layui-btn layui-btn-warm layui-table-tools" lay-event="exbtn" shiro:hasPermission="hr:talentpool:add">
    	<p class="dhicon dh-external-link-square" style="color:white;font-size:14px"><span class="fa_span">调入</span></p>
	</div>
	<div style="margin-left:10px;width:290px;display:inline-flex;vertical-align: middle;">
		<span class="f_red">*</span>所属公司：
		<input type="text" class="layui-input" id="cidName" onclick="getCompany()" style="width:66%" readonly/>
			<i class="layui-icon layui-icon-more" onclick="getCompany()" style="position: relative;right:25px"></i>
	</div>
</script>
<script type="text/html" id="date_dYpRq">
	<input type="text" lay-verify="date" value="{{d.dYpRq?d.dYpRq:''}}" placeholder="请选择时间" readonly class="layui-input layui-table-date" style="text-align: center;padding: 0;width: calc(100% + 16px);"/>
</script>
<script type="text/html" id="date_dCsRq">
	<input type="text" lay-verify="date" value="{{d.dCsRq?d.dCsRq:''}}" placeholder="请选择时间" readonly class="layui-input layui-table-date" style="text-align: center;padding: 0;width: calc(100% + 16px);"/>
</script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "hr/talentpool",
		fields = [[${fields}]];
	/*]]>*/
</script>
<script type="text/javascript">
var str=[],$,layer,form,table,laydate,listData,vCpFl='';
var gridColumnsBody=[
	{type:'numbers', fixed: 'left'}
	,{field:'userName', title: '姓名',width:150,align: 'center', edit: 'text'}
	,{field:'position', title: '岗位',width:150,align: 'center', edit: 'text'}
	,{field:'vBq', title: '标签',width:150,align: 'center',edit: 'text'}
	,{field:'vJlBh', title: '简历编号',width:150,align: 'center', edit: 'text'}
	,{field:'vYpZw', title: '应聘职位',width:150,align: 'center', edit: 'text'}
	,{field:'vFfCs', title: '发布城市',width:150,align: 'center', edit: 'text'}
	,{field:'dYpRq', title: '应聘日期',width:150,align: 'center',templet:'#date_dYpRq'}
	,{field:'vXb', title: '性别',width:150,align: 'center', edit: 'text'}
	,{field:'dCsRq', title: '出生日期',width:150,align: 'center',templet:'#date_dCsRq'}
	,{field:'vJzd', title: '目前居住地',width:150,align: 'center', edit: 'text'}
	,{field:'vGj', title: '户口/国籍',width:150,align: 'center', edit: 'text'}
	,{field:'vGzNx', title: '工作年限',width:150,align: 'center', edit: 'text'}
	,{field:'vXl', title: '学历/学位',width:150,align: 'center', edit: 'text'}
	,{field:'vXx', title: '毕业学校',width:150,align: 'center', edit: 'text'}
	,{field:'vZy', title: '专业',width:150,align: 'center', edit: 'text'}
	,{field:'vTel', title: '联系电话',width:150,align: 'center', edit: 'text'}
	,{field:'vMail', title: '电子邮件',width:150,align: 'center', edit: 'text'}
	,{field:'vDz', title: '地址',width:150,align: 'center', edit: 'text'}
	,{field:'vSjGs', title: '最近一家公司',width:150,align: 'center', edit: 'text'}
	,{field:'vSgZw', title: '最近一个职位',width:150,align: 'center', edit: 'text'}
	,{field:'vNsr', title: '目前年收入',width:150,align: 'center', edit: 'text'}
	,{field:'vQwXz', title: '期望薪资',width:150,align: 'center', edit: 'text'}
	,{field:'vQzZt', title: '求职状态',width:150,align: 'center', edit: 'text'}
	,{fixed: 'right', title: '操作',width:150,align: 'center', toolbar: '#barDh'}
	]
layui.use(['table','form','layer','jquery','laydate'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate=layui.laydate;
	$.tablelist.init({
        elem: '#dhtable'
	    ,modalName: "人才信息"
        ,page:false
        ,limit:10000
        ,data: []
        ,cols: [gridColumnsBody
   		]
		,toolbar: '#toolbar'
		,height:'full-40'
		,done:function(res, curr, count){
      		listData = table.cache.dhtable;
			tableDate(res,listData);
// 			$.each(gridColumnsBody,function(i,v){//不可编辑添加样式
// 				if(!(v.edit && v.field))$($('.layui-table-view')[0]).find(".layui-table-main [data-field='"+v.field+"']").css('background-color','#F2F2F2');
// 			})
		}
	});
  	//头工具栏事件
	table.on('toolbar(ftable)', function(obj){
    	switch(obj.event){
      	case 'addbtn':
      		listData = table.cache.dhtable;
      		listData.push({"deleted":0}),
        	table.reload('dhtable',{data : listData});
			break;
      	case 'exbtn':
      		$.modal.open('选择人才信息',prefix+'/select','1035','700',function(index){
		        var res = window["layui-layer-iframe" + index].callbackdata();
		        if(res.length > 0){
		        	$.each(res,function(i,v){
		        		table.cache.dhtable.push(v);
		        	});
		        	table.reload('dhtable',{data:table.cache.dhtable});
		       	 	layer.closeAll();
		        }else{
		            layer.msg("请将选择人才信息移到下方表格！");
		        }
		    });
      		break;
    	};
	});
	//监听行事件
	table.on('tool(ftable)', function (obj) {
		var data = obj.data, event = obj.event;
		switch(event){
			case "del":
				obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
				listData=table.cache.dhtable;
				for(var i=0; i < listData.length; i++)if(!listData[i] || listData[i].length==0)listData.splice(i, 1);//删除一项
				table.reload('dhtable',{data : listData});
			break;
		}
	});
    form.on('submit(btn_save)', function(data){
    	if($('#cid').val()){
    		if(table.cache.dhtable.length){
        		$.each(table.cache.dhtable,function(v,k){
        			k['cid']=$('#cid').val();
        			k['cidName']=$('#cidName').val();
        		})
            	$.operate.post(prefix + "/addpost", {'talentPoolItems':JSON.stringify(table.cache.dhtable, null, 2)}, function(res){
            		if(res.code == 0)goUrl(prefix + "/add")
            	});
    		}else{
    			layer.msg("无数据！", {icon:7});
    		}
    	}else{
    		layer.msg("请选择所属公司！", {icon:7});
    	}
	}); 
});
function tableDate(res, listData){
	$(".layui-table-date").each(function (i) {
		laydate.render({
			elem: this,
			type: 'date',
			trigger: 'click',
			done: function (value, date) {
				var elemtr = $(this.elem).parents('tr').index();
				var elem = $(this.elem).parents('td');
				var datafield = elem.attr("data-field");
				if (res && listData[elemtr]) {
					listData[elemtr][datafield] = value;
				}
			}
		});
	});
}
function getCompany(){//选择式所属公司
    $.modal.open('选择所属公司', '/base/company/select', null, null, function(index){
        var res = window["layui-layer-iframe" + index].callbackdata();
        if(res=="none" || !res){//没有选中时
           	layer.msg("请选择！", {icon:7});
		}else{
			$('#cid').val(res.vId);
			$('#cidName').val(res.vName);
  	        layer.close(index);
		}
    });
}
</script>
</body>
</html>